
layui.use(['upload', 'form', 'laydate'], function () { //此段代码必不可少
    var form = layui.form;
    var upload = layui.upload;
    var laydate = layui.laydate;
    laydate.render({
        elem: '#entranceTime'
    })
    //执行实例
    var uploadInst = upload.render({
        elem: '#icon_change', //绑定元素

        url: LOCALHOSTURL+'/upload', //上传接口

        accept: 'images',
        acceptMime: 'image/*',
        xhrFields: {
            withCredentials: true //默认情况下，标准的跨域请求是不会发送cookie的
        },
        headers: {
            "Authorization": $.cookie("token")
        },
        crossDomain: true,
        before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#icon').attr('src', result); //图片链接（base64）
            });
        },
        // done: function (res) {
        //上传完毕回调
        //     return layer.msg(res.message);
        // ("#icon").attr("src", res.iconName);
        // },
        error: function () {
            // 请求异常回调
            // 演示失败状态，并实现重传
            // var demoText = $('#demoText');
            // demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
            // demoText.find('.demo-reload').on('click', function(){
            //     uploadInst.upload();
            // });
            // return layer.alert('上传失败');
        }
    });
});
